package Interview;

import java.util.Scanner;

/**
 * Created by loso on 2017/3/18.
 */
public class bestbrain3602017 {

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            StringBuilder in = new StringBuilder(input.nextLine());
            String s1 = input.nextLine();
            String s2 = input.nextLine();

            int index1 = in.indexOf(s1);
            int index2 = in.indexOf(s2,index1 + s1.length());

            in = new StringBuilder(in.reverse());
            int index3 = in.indexOf(s1);
            int index4 = in.indexOf(s2,index3 + s1.length());

            if ((index2 == -1 || index1 == -1) && (index3 == -1 || index4 == -1)){
                System.out.println("invalid");
                continue;
            }
            if (index3 == -1 || index4 == -1){
                System.out.println("forward");
                continue;
            }
            if (index2 == -1 || index1 == -1){
                System.out.println("backward");
                continue;
            }
            System.out.println("both");
        }
    }

}


